package lesson02;

public class Demo_201 {
    private  static  long num=100000;
    public static void main(String[] args) throws InterruptedException {
        serial();
        concurrency();

    }

    public  static  void  serial(){
        long begin= System.currentTimeMillis();
        long a=0,b=0;
        for(long i=0;i<num;i++){
            a++;
        }
        for(long i=0;i<num;i++){
            b++;
        }
        long end= System.currentTimeMillis();
        System.out.println("串行"+(end - begin));
    }
    public static  void  concurrency() throws InterruptedException {

        Thread thread1=new Thread(new Runnable() {
            @Override
            public void run() {
                Thread thread=Thread.currentThread();
                System.out.println(thread.getName());
                int a=0;
                for(long i=0;i<num;i++){
                    a++;
                }
            }
        },"我是线程1");
        Thread thread2=new Thread(new Runnable() {
            @Override
            public void run() {
                int b=0;
                for(long i=0;i<num;i++){
                    b++;
                }
            }
        },"我是线程2");
        long begin= System.currentTimeMillis();
        thread1.start();
        thread2.start();
        thread1.join();
        thread2.join();
        long end= System.currentTimeMillis();
        System.out.println("并行"+(end - begin));
    }

}



